<?php
	if(!empty($_POST)) {
		// Store configuration:
		$handle  = fopen('../config.inc.php', 'w');
		$content = '<?php
// dataStruct configuration file

$dbname   = "'.$_POST['dbname'].'";
$dbuser   = "'.$_POST['dbuser'].'";
$dbpass   = "'.$_POST['dbpass'].'";
$dbhost   = "'.$_POST['dbhost'].'";
$dbprefix = "'.$_POST['dbprefix'].'";
?>';
		fwrite($handle, $content);
		fclose($handle);
		// Setup the database:
		include_once('setupdatabase.php');
		// Header back to the index:
		header('Location: ../index.php');
	}
?>
<html>
	<head>
		<title>DataStruct Setup</title>
		<style type="text/css">
			label { display: block; }
		</style>
	</head>
	<body>
		<h1>DataStruct setup</h1>
		<hr />
		<form method="post" action="index.php">
			<label>Database name:</label>
			<input type="text" name="dbname" /> * Please make sure the database exists!
			
			<label>Database username:</label>
			<input type="text" name="dbuser" />
			
			<label>Database password:</label>
			<input type="password" name="dbpass" />
			
			<label>Database host:</label>
			<input type="text" name="dbhost" value="localhost" />
			
			<label>Database prefix:</label>
			<input type="text" name="dbprefix" />
			
			<label>&nbsp;</label>
			<input type="submit" value="Setup" />
		</form>
	</body>
</html>